from guizero import App, PushButton, Text
import serial
import time

xiaoRP2040 = serial.Serial("COM29", 9600)
time.sleep(2)

def led_on():
    xiaoRP2040.write(b'1')
    state.value = "LED On"

def led_off():
    xiaoRP2040.write(b'0')
    state.value = "LED Off"

app = App(title="LED Control by Serial", width=400, height=200)
app.bg = "lightblue"

Text(app, text="LED Control by Serial", size=16)

button1 = PushButton(app, text="Encender LED", command=led_on, width=20)
button1.bg = "green"
button2 = PushButton(app, text="Apagar LED", command=led_off, width=20)
button2.bg = "red"

state = Text(app, text="LED State")

app.display()